<template>
	<view>
		<navbar title="我的任务" :autoBack="true"></navbar>
		<scroll-view scroll-y="true" class="scbox">
			<view class="con">
				<view class="con__box">
					<view class="con__box__top">
						<view class="u-flex u-flex-y-center">
							<image src="/static/stak/dh.png" class="con__box__top__icon" @click="call(taskinfo.customerMobile)" v-if="taskinfo.type==1" mode=""></image>
							<image src="/static/tool/bf.png" class="con__box__top__icon" @click="clickbaf(taskinfo)" v-if="taskinfo.type==4" mode=""></image>
							<image src="/static/tool/wx.png" class="con__box__top__icon" v-if="taskinfo.type==3" mode=""></image>
							<image src="/static/tool/dx.png" class="con__box__top__icon" v-if="taskinfo.type==2" mode=""></image>
							<view class="con__box__top__title u-flex">
								<view class="" style="margin-right: 0.5rem;">
									<text v-if="taskinfo.type==1">打电话</text><text
										v-if="taskinfo.type==3">发微信</text><text v-if="taskinfo.type==2">发短信</text><text
										v-if="taskinfo.type==4">拜访</text>
								</view> {{$u.timeFormat(new Date(taskinfo.noticetime).getTime(), 'mm月dd日')}}
								周{{weeklist[new Date(taskinfo.createtime).getDay()]}} {{$u.timeFormat(new Date(taskinfo.noticetime).getTime(), 'hh:MM')}}
							</view>
						</view>
						<view class="u-flex u-flex-y-center u-flex-between" style="margin: 15rpx 0 36rpx;">
							<view class="con__box__top__jdbox">
								<view class="con__box__top__jdbox__jd" style="width: 20%;">

								</view>
							</view>
							<view class="con__box__top__jdtext">
								0/1
							</view>
						</view>
						<view class="con__box__top__info" @click="iszk=!iszk">
							<view class="con__box__top__info__text">
								<view class="" style="width:140rpx;">
									创建人
								</view>
								<view class="" style="flex: 1;">
									{{taskinfo.createName}}
								</view>
								<u-icon name="arrow-up" color="#78797E" size="30rpx"></u-icon>
							</view>
							<view class="" v-if="iszk">
								<view class="con__box__top__info__text">
									<view class="" style="width:140rpx;">
										执行人
									</view>
									<view class="">
										{{taskinfo.makerName}}
									</view>
								</view>
								<view class="con__box__top__info__text">
									<view class="" style="width:140rpx;">
										提醒时间
									</view>
									<view class="">
										{{taskinfo.endtime}}
									</view>
								</view>
								<view class="con__box__top__info__text">
									<view class="" style="width:140rpx;">
										话术
									</view>
									<view class="">
										{{taskinfo.content}}
									</view>
								</view>
							</view>

						</view>
						<view class="con__box__top__time">
							<image src="/static/stak/jzsj.png" class="con__box__top__time__icon" mode=""></image>
							截止时间:{{taskinfo.endtime}}
						</view>
					</view>

					<u-gap height="25rpx" bgColor="#F4F5FA"></u-gap>
					<u-sticky :offsetTop="0" :customNavHeight='0'>
						<view class="con__box__tab">
							<view class="con__box__tab__item" v-for="(item,index) in tablist" :key="index"
								@click="curtab=index,status=tablist[curtab].status,getlist()"
								:class="curtab==index?'active':''">
								{{item.text}}({{item.num}})
							</view>
						</view>
					</u-sticky>
					<view class="" v-if="list.length>0">
						<view class="con__box__item" v-for="(item,index) in list" :key="index">
							<view class="con__box__item__dian">
						
							</view>
							<view class="con__box__item__name">
								{{customername}}
							</view>
							<view class="con__box__item__status" v-if="item.status==1">
								未完成
							</view>
							<view class="con__box__item__status" v-if="item.status==2">
								已完成
							</view>
							<image src="/static/stak/dh2.png" class="con__box__item__icon" @click="call(item.customerMobile)" v-if="item.type==1" mode="">
							</image>
							<image src="/static/tool/dx1.png" class="con__box__item__icon" v-if="item.type==2" mode="">
							</image>
							<image src="/static/tool/wx1.png" class="con__box__item__icon" v-if="item.type==3" mode="">
							</image>
							<image src="/static/tool/bf1.png" class="con__box__item__icon" @click="clickwc(item)" v-if="item.type==4" mode="">
							</image>
						</view>
					</view>
					<u-empty v-else></u-empty>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import sale from '@/api/_sale.js'
	export default {
		data() {
			return {
				weeklist: ['日', '一', '二', '三', '四', '五', '六'],
				iszk: true,
				tablist: [{
						text: '待执行',
						num: 0,
						status: 1
					},
					{
						text: '已执行',
						num: 0,
						status: 2
					},
				],
				curtab: 0,
				status: 1,
				list: [],
				taskinfo: {},
				id:null,
				customerid:null,
				customername:''
			};
		},
		methods: {
			async getlist() {
				this.getnum()
				let res = await sale.customerTask({
					id:this.customerid,
					status:this.status
				})
				if (res.data.code == 1) {
					this.list = res.data.data
				}

			},
			clickwc(item){
				uni.showModal({
					title: '确定完成该任务？',
					success(r) {
						if (r.confirm) {
							sale.editTask({
								id: item.id,
								status: 2
							}).then(res => {
								if (res.data.code == 1) {
									_this.getlist()
								}
							})
				
						}
					}
				})
			},
			async getinfo() {
				let res = await sale.taskMyInfo({id:this.id})
				if (res.data.code == 1) {
					this.taskinfo = res.data.data
				}
			},
			async getnum(){
				let res = await sale.getTaskCount({customer_id:this.customerid})
				if(res.data.code==1){
					this.tablist[0].num=res.data.data.unAbleCount
					this.tablist[1].num=res.data.data.successCount
				}
			},
			clickbaf(item){
				this.$store.commit('setcustomer', {
					id:item.customer_id,
					username:item.customerName
				})
				this.navto('/pages/tool/sign')
			}
		},
		onLoad(o) {
			this.id=o.id
			this.customerid=o.customerid
			this.customername=o.customername
			this.getinfo()
			this.getlist()
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f8f8f8;
	}

	.con {
		padding: 20rpx 30rpx;

		&__box {
			background: #FFFFFF;
			border-radius: 20rpx;

			&__top {
				padding: 34rpx 30rpx 25rpx;

				&__icon {
					width: 85rpx;
					height: 85rpx;
					margin-right: 19rpx;
				}

				&__title {
					font-family: PingFang SC;
					font-weight: 800;
					font-size: 32rpx;
					color: #010101;
					line-height: 32rpx;
				}

				&__jdbox {
					width: 560rpx;
					height: 11rpx;
					background: #EDEDED;
					border-radius: 6rpx;

					&__jd {
						background-color: #3262FD;
						height: 11rpx;
						border-radius: 6rpx;
					}
				}

				&__jdtext {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 30rpx;
					color: #010101;
					line-height: 23rpx;
				}

				&__info {
					padding: 29rpx 8rpx 1rpx 23rpx;
					background: #F4F5FA;
					border-radius: 10rpx;
					margin-bottom: 25rpx;

					&__text {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 26rpx;
						color: #78797E;
						line-height: 24rpx;
						margin-bottom: 36rpx;
						display: flex;
						align-items: center;
					}
				}

				&__time {
					height: 88rpx;
					background: #F4F5FA;
					border-radius: 10rpx;
					display: flex;
					align-items: center;
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 28rpx;
					color: #3262FD;
					line-height: 28rpx;
					padding: 0 23rpx;

					&__icon {
						width: 35rpx;
						height: 40rpx;
						margin-right: 26rpx;
					}
				}
			}

			&__tab {
				display: flex;
				align-items: center;
				height: 110rpx;
				background-color: #fff;
				border-radius: 20rpx;

				&__item {
					;
					font-family: PingFang SC;
					font-weight: bold;
					font-size: 28rpx;
					color: #686C70;
					line-height: 28rpx;
					padding: 0 26rpx;
				}

				.active {
					color: #3262FD;
					font-size: 30rpx;
				}
			}

			&__item {
				padding: 0 34rpx 36rpx 31rpx;
				display: flex;
				align-items: center;

				&__dian {
					width: 14rpx;
					height: 14rpx;
					background: #3262FD;
					border-radius: 50%;
					opacity: 0.58;
					margin-right: 8rpx;
				}

				&__name {
					font-family: PingFang SC;
					font-weight: bold;
					font-size: 30rpx;
					color: #1D1D1D;
					line-height: 28rpx;
					flex: 1;
				}

				&__status {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 26rpx;
					color: #78797E;
					line-height: 26rpx;
					margin-right: 19rpx;
				}

				&__icon {
					width: 107rpx;
					height: 67rpx;
				}
			}
		}
	}
</style>